﻿using Scenario_Editor.Tools;
using SharpDX;
using System;
using System.Drawing;
using System.Windows.Forms;
using WorldRacing2.Terrain;

namespace WorldRacing2.Toolstrips
{
    internal class TerrainToolstrip
    {
        private ToolStripMenuItem updateDiffuseColorToolStripMenuItem1;
        private ToolStripMenuItem exportDiffuseColorToolStripMenuItem;
        private ToolStripMenuItem importDiffuseColorToolStripMenuItem;
        private ToolStripMenuItem exportVertexColorToolStripMenuItem;
        private ToolStripMenuItem importVertexColorToolStripMenuItem;

        public ITerrain Terrain { get; set; }

        public TerrainToolstrip()
        {
            //
            // updateDiffuseColorToolStripMenuItem1
            //
            this.updateDiffuseColorToolStripMenuItem1 = new ToolStripMenuItem();
            this.updateDiffuseColorToolStripMenuItem1.Name = "updateDiffuseColorToolStripMenuItem1";
            this.updateDiffuseColorToolStripMenuItem1.Size = new System.Drawing.Size(330, 22);
            this.updateDiffuseColorToolStripMenuItem1.Text = "Update Diffuse Color";
            this.updateDiffuseColorToolStripMenuItem1.Click += new System.EventHandler(this.updateDiffuseColorToolStripMenuItem_Click);
            //
            // exportDiffuseColorToolStripMenuItem
            //
            this.exportDiffuseColorToolStripMenuItem = new ToolStripMenuItem();
            this.exportDiffuseColorToolStripMenuItem.Name = "exportDiffuseColorToolStripMenuItem";
            this.exportDiffuseColorToolStripMenuItem.Size = new System.Drawing.Size(330, 22);
            this.exportDiffuseColorToolStripMenuItem.Text = "Export Diffuse Color";
            this.exportDiffuseColorToolStripMenuItem.Click += new System.EventHandler(this.exportDiffuseColorToolStripMenuItem_Click);
            //
            // importDiffuseColorToolStripMenuItem
            //
            this.importDiffuseColorToolStripMenuItem = new ToolStripMenuItem();
            this.importDiffuseColorToolStripMenuItem.Name = "importDiffuseColorToolStripMenuItem";
            this.importDiffuseColorToolStripMenuItem.Size = new System.Drawing.Size(330, 22);
            this.importDiffuseColorToolStripMenuItem.Text = "Import Diffuse Color";
            this.importDiffuseColorToolStripMenuItem.Click += new System.EventHandler(this.importDiffuseColorToolStripMenuItem_Click);
            //
            // exportVertexColorToolStripMenuItem
            //
            this.exportVertexColorToolStripMenuItem = new ToolStripMenuItem();
            this.exportVertexColorToolStripMenuItem.Name = "exportVertexColorToolStripMenuItem";
            this.exportVertexColorToolStripMenuItem.Size = new System.Drawing.Size(330, 22);
            this.exportVertexColorToolStripMenuItem.Text = "Export Vertex Color";
            this.exportVertexColorToolStripMenuItem.Click += new System.EventHandler(this.exportVertexColorToolStripMenuItem_Click);
            //
            // importVertexColorToolStripMenuItem
            //
            this.importVertexColorToolStripMenuItem = new ToolStripMenuItem();
            this.importVertexColorToolStripMenuItem.Name = "importVertexColorToolStripMenuItem";
            this.importVertexColorToolStripMenuItem.Size = new System.Drawing.Size(330, 22);
            this.importVertexColorToolStripMenuItem.Text = "Import Vertex Color";
            this.importVertexColorToolStripMenuItem.Click += new System.EventHandler(this.importVertexColorToolStripMenuItem_Click);
        }

        private void exportDiffuseColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Bitmap (*.png)|*.png";
            sfd.FileName = "DiffuseColor.png";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TerrainTools.ExportDiffuseColor(this.Terrain, sfd.FileName);
            }
        }

        private void exportVertexColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "Bitmap (*.png)|*.png";
            sfd.FileName = "VertexColor.png";
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TerrainTools.ExportVertexColor(this.Terrain, sfd.FileName);
            }
        }

        private void importDiffuseColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Bitmap (*.png)|*.png";
            ofd.FileName = "DiffuseColor.png";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TerrainTools.ImportDiffuseColor(this.Terrain, (Bitmap)Bitmap.FromFile(ofd.FileName));
            }
        }

        private void importVertexColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Bitmap (*.png)|*.png";
            ofd.FileName = "DiffuseColor.png";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TerrainTools.ImportVertexColor(this.Terrain, (Bitmap)Bitmap.FromFile(ofd.FileName));
            }
        }

        private void updateDiffuseColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TerrainTools.SetDiffuseColor(this.Terrain, new Color4(1.0f, 0.4f, 0.4f, 0.4f));
        }

        public ToolStripItem[] GetToolstripItems()
        {
            ToolStripMenuItem root = new ToolStripMenuItem("Terrain");

            root.DropDownItems.AddRange(new ToolStripItem[]
                {
                  this.updateDiffuseColorToolStripMenuItem1,
                  this.exportDiffuseColorToolStripMenuItem,
                  this.importDiffuseColorToolStripMenuItem,
                  this.exportVertexColorToolStripMenuItem
                });

            return new ToolStripItem[] { root };
        }
    }
}